library(janitor)
library(sf)
sf_use_s2(FALSE)
library(tmap)
tmap_mode('view')
library(tidyverse)
options(knitr.kable.NA = '')Data summary
Read data
metadata <- read_csv('data/metadata.csv', guess_max = 4000) Summary
Code
metadata %>%
summarise(`Number of records` = n(),
`Number of sources` = n_distinct(source_name),
`Number of taxa` = n_distinct(taxa),
`Animalia records` = sum(kingdom == 'Animalia'),
`Plantae records` = sum(kingdom == 'Plantae'),
`Fungi records` = sum(kingdom == 'Fungi'),
Countries = n_distinct(gadm_level_0),
`Sub-national territories` = n_distinct(gadm_level_1)) %>%
t() %>% `colnames<-`(c("N")) %>%
kableExtra::kbl(booktabs = T) %>%
kableExtra::kable_styling(latex_options = c('striped', 'hold_position'))| N | |
|---|---|
| Number of records | 3200 |
| Number of sources | 2091 |
| Number of taxa | 483 |
| Animalia records | 2189 |
| Plantae records | 899 |
| Fungi records | 105 |
| Countries | 170 |
| Sub-national territories | 223 |
Geographic coverage
Code
# sources per continent
metadata %>%
separate_rows(continent, sep = '\\|') %>%
mutate(continent = str_squish(continent)) %>%
group_by(continent) %>%
summarise(n_sources = ifelse(n_distinct(source_name, na.rm = TRUE)==0,
0, n_distinct(source_name, na.rm = TRUE))) %>%
arrange(desc(n_sources)) %>%
rename(`Number of sources`=n_sources) %>%
adorn_totals('row') %>%
kableExtra::kbl(booktabs = T) %>%
kableExtra::kable_styling(latex_options = c('striped', 'hold_position')) | continent | Number of sources |
|---|---|
| Europe | 1439 |
| Asia | 272 |
| Africa | 143 |
| South America | 116 |
| North America | 112 |
| Oceania | 31 |
| Antarctica | 7 |
| Total | 2120 |
Code
# records per continent
metadata %>%
separate_rows(continent, sep = '\\|') %>%
mutate(continent = str_squish(continent)) %>%
group_by(continent) %>%
summarise(n_records = n()) %>%
arrange(desc(n_records)) %>%
rename(`Number of records`=n_records) %>%
adorn_totals('row') %>%
kableExtra::kbl(booktabs = T) %>%
kableExtra::kable_styling(latex_options = c('striped', 'hold_position')) | continent | Number of records |
|---|---|
| Europe | 2182 |
| Asia | 470 |
| Africa | 205 |
| North America | 156 |
| South America | 150 |
| Oceania | 62 |
| Antarctica | 7 |
| Total | 3232 |
Code
# Europe
metadata %>%
separate_rows(continent, sep = '\\|') %>%
mutate(continent = str_squish(continent)) %>%
filter(continent == 'Europe') %>%
group_by(kingdom) %>%
summarise(n_records = n()) %>%
arrange(desc(n_records)) %>%
rename(`Number of records`=n_records) %>%
adorn_totals('row') %>%
kableExtra::kbl(booktabs = T) %>%
kableExtra::kable_styling(latex_options = c('striped', 'hold_position')) | kingdom | Number of records |
|---|---|
| Animalia | 1551 |
| Plantae | 549 |
| Fungi | 75 |
| Protozoa | 6 |
| Chromista | 1 |
| Total | 2182 |
Code
# asia
metadata %>%
separate_rows(continent, sep = '\\|') %>%
mutate(continent = str_squish(continent)) %>%
filter(continent == 'Asia') %>%
group_by(kingdom) %>%
summarise(n_records = n()) %>%
arrange(desc(n_records)) %>%
rename(`Number of records`=n_records) %>%
adorn_totals('row') %>%
kableExtra::kbl(booktabs = T) %>%
kableExtra::kable_styling(latex_options = c('striped', 'hold_position'))| kingdom | Number of records |
|---|---|
| Animalia | 277 |
| Plantae | 175 |
| Fungi | 18 |
| Total | 470 |
Code
# germany
metadata %>%
filter(!is.na(class)) %>%
filter(gadm_level_0 == 'Germany') %>%
group_by(kingdom, class) %>%
summarise(n_records = n()) %>%
arrange(desc(n_records)) %>%
ungroup %>% slice_head(n=5) %>%
rename(`Number of records`=n_records) %>%
adorn_totals('row') %>%
kableExtra::kbl(booktabs = T) %>%
kableExtra::kable_styling(latex_options = c('striped', 'hold_position')) | kingdom | class | Number of records |
|---|---|---|
| Animalia | Insecta | 544 |
| Animalia | Aves | 35 |
| Animalia | Mammalia | 28 |
| Animalia | Amphibia | 27 |
| Animalia | Arachnida | 27 |
| Total | - | 661 |
Code
# usa
metadata %>%
filter(iso_2 == 'US') %>%
group_by(kingdom, taxa) %>%
summarise(n_records = n()) %>%
arrange(desc(n_records)) %>%
rename(`Number of records`=n_records) %>%
adorn_totals('row') %>%
kableExtra::kbl(booktabs = T) %>%
kableExtra::kable_styling(latex_options = c('striped', 'hold_position')) | kingdom | taxa | Number of records |
|---|---|---|
| Animalia | Fauna | 1 |
| Fungi | Fungi | 1 |
| Plantae | Flora | 1 |
| Total | - | 3 |
Code
world <- geodata::world(resolution = 3, level = 0, path = 'data/')
world_records <- left_join(st_as_sf(world), metadata %>%
separate_rows(iso_3, sep = '\\|') %>%
select(iso_2, GID_0=iso_3, source_name)) %>%
group_by(GID_0, NAME_0) %>%
summarise(n_sources = ifelse(n_distinct(source_name, na.rm = TRUE)==0,
0, n_distinct(source_name, na.rm = TRUE)),
iso_2_string = ifelse(n_sources>0,
paste(iso_2, collapse = ';'), NA)) %>%
ungroup() %>% st_cast() %>% st_set_crs(4326)
plot_figure_1 <- tm_shape(world_records %>%
select(-iso_2_string) %>%
mutate(n_sources=ifelse(n_sources==0,
NA, n_sources))) +
tm_polygons(fill = 'n_sources',fill_alpha = 0.9,
col='grey40', col_alpha = 0.2,
fill.scale = tm_scale_intervals(n = 6,
#style = 'jenks',
breaks = c(1,5,10,20,100,979),
values = 'brewer.reds',
value.na = 'grey80',
label.na = '0'),
fill.legend = tm_legend(item.space = 0, item.na.space = 0,
title = 'Number of sources',
reverse=T,
# frame=F,
frame.lwd = 0.1,
bg.color = 'white')) +
tm_layout(legend.outside = T,
legend.position = c('left','bottom'), frame=F) +
tm_crs(property='global')
tmap_mode('plot')
plot_figure_1Code
tmap_mode('view')
plot_figure_1